#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct pii{
    int fi,se;
    bool operator <(const pii &_)const{
        if(fi != _.fi)return fi < _.fi;
        return se < _.se;
    }
};
inline int fr(int &x){
    char ch = getchar();x = 0;int f = 1;
    for(;!isdigit(ch);ch = getchar())if(ch == '-')f = -1;
    for(;isdigit(ch);ch = getchar())x = (x << 1) + (x << 3) + (ch ^ 48);
    return x *= f;
}
int n,m,k,a[100010],c[100010],T,X[5];
ll ans[200010],lans,tr[500010],nonam[500010];
bool d[25][200010];
void DAAT(int x){
    int h = ceil(log2(x)),xid = (1 << k) + x - 1;
    tr[xid] = x,nonam[xid] = 0;
    for(int j = 1,id = xid >> 1;j <= h;j++,id >>= 1){
        if(!d[j][id - (1 << (k - j + 1)) + 1]){
            if(a[tr[id << 1]] >= j){
                tr[id] = tr[id << 1];
                if(nonam[id << 1])nonam[id] = nonam[id << 1] + nonam[id << 1 | 1];
            }
            else{
                tr[id] = tr[id << 1 | 1];
                if(nonam[id << 1])nonam[id] = nonam[id << 1] + nonam[id << 1 | 1];
            }
        }
        else{
            if(a[tr[id << 1 | 1]] < j){
                tr[id] = tr[id << 1];
                if(nonam[id << 1 | 1])nonam[id] = nonam[id << 1] + nonam[id << 1 | 1];
            }
            else{
                tr[id] = tr[id << 1 | 1];
                if(nonam[id << 1 | 1])nonam[id] = nonam[id << 1] + nonam[id << 1 | 1];
            }
        }
    }
    ans[x] = tr[xid >> h] + nonam[xid >> h];
    cout << h << ' ' << x << ' ' << ans[x] << '\n';
}
int main(){
    //freopen("arena.in","r",stdin);
    //freopen("arena.out","w",stdout);
    k = ceil(log2(fr(n)));fr(m);
    for(int i = 1;i <= n;i++)fr(a[i]);
    for(int i = 1;i <= m;i++)fr(c[i]);
    char ch = getchar();
    for(int i = 1;i <= k;i++){
        while(ch == '\r' || ch == '\n')ch = getchar();
        for(int j = 1;j <= (1 << (k - i));j++,ch = getchar())d[i][j] = ch ^ 48;
    }
    fr(T);
    while(T--){
    memset(ans,0,sizeof(ans));memset(tr,0,sizeof(tr));memset(nonam,0,sizeof(nonam));
    for(int i = 0;i < 4;i++)fr(X[i]);
    for(int i = 1;i <= n;i++)cout << (a[i] ^= X[i % 4]) << ' ';cout << '\n';
    for(int i = 1;i <= n;i++)nonam[(1 << k) + i - 1] = i;
    for(int i = 1;i <= n;i++)DAAT(i);
    lans = 0;
    for(int i = 1;i <= m;i++)lans ^= ans[c[i]] * i;
    cout << lans << '\n';
    for(int i = 1;i <= n;i++)a[i] ^= X[i % 4];
    }
    return 0;
}
